<template>
  <div class="view-wrapper">
    <!-- app-container -->
    <div class="head">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="" prop="">
          <el-input v-model="queryParams.brandName" placeholder="请输入品牌名称" clearable />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <div class="listBox_head">
        <el-button type="primary" style="margin: 10px 0 20px" @click="addClick">批量配置</el-button>
      </div>
      <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="tabList"
        stripe
        border
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <!-- <el-table-column label="序号" align="center" type="index" width="64px" /> -->
        <el-table-column label="品牌id" prop="brandId"></el-table-column>
        <el-table-column label="品牌名称" prop="brandName"></el-table-column>
        <el-table-column label="积分发放方式" prop="groupName">
          <template slot-scope="scope">
              <dict-tag :options="statusList" :value="scope.row.grantMethod" />
            </template>
        </el-table-column>
        <el-table-column label="积分类型" prop="groupName">
          <template slot-scope="scope">
            <dict-tag :options="integralTypeList" :value="scope.row.integralType" />
          </template>
        </el-table-column>
        <el-table-column label="发放数额" prop="grantValue"></el-table-column>
        <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width" fixed="right">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="editClick(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList"></pagination> -->
    </div>
    <Dialog :id="dialogId" :ids="ids" :pathType='pathType' v-bind="$attrs" v-if="dialogVisible" :visible.sync="dialogVisible" @success="_handleSuccess">
    </Dialog>
  </div>
</template>

<script>
  import {
    jtkRuleList,
    batchDownload,
    changeShowFlag
  } from "@/api/integralOperation/jtkConfiguration";
  import Dialog from "./components/dialog";
  import ExportExcelButton from "@/components/ExportExcelButton/index";
  
  export default {
    name: "",
    components: {
      Dialog,
      ExportExcelButton
    },
    data() {
      return {
        dialogId: '',
        dialogVisible: false,
        // 遮罩层
        loading: false,
        // 导出遮罩层
        // 总条数
        total: 0,
        statusList: [], //状态字典数组
        integralTypeList: [],
        //表格数据
        tabList: [],
        pathType: 'add',
        // 查询参数
        queryParams: {
          brandName: '', //活动名称
        },
        imgList: [],
        ids: [],
        isDown: false,
      };
    },
    computed: {
      ExportParams() {
        const params = {
          ids: this.ids,
        };
        return params;
      },
    },
    created() {
      this.getDict()
      this.getList();
    },
    methods: {
      //获取字典
      getDict() {
        var dictType = "jutuike_integral_grant_method,jutuike_integral_type";
        this.$getSelectList(dictType)
        .then((res) => {
          var arr = [{
            id: "",
            value: "全部",
          }, ];
          this.statusList = res.result[0].dictList
          this.integralTypeList = res.result[1].dictList;
        })
        .finally(() => {

        });
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        jtkRuleList(this.queryParams).then(response => {
          this.tabList = response.result;
          this.loading = false;
        });
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
        console.log('val',val)
        var selList = []
        val.forEach(item => {
          selList.push(item.id)  
        });
        this.ids = selList
        console.log('this.ids',this.ids)
      },
      // 表单重置
      reset() {
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          brandName: '', //活动名称
        };
        // this.resetForm("form");
        this.handleQuery()
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        // this.resetForm("queryForm");
        this.reset();
      },
      //新增
      addClick() {
        if(this.ids.length == 0){
          this.$message.error('请选择配置的品牌')
          return
        }
        this.dialogId = null
        this.dialogVisible = true;
        this.pathType = 'add'
      },
      // 编辑
      editClick(row) {
        this.dialogId = row.id
        this.pathType = 'edit'
        console.log(this.dialogStatus)
        this.dialogVisible = true;
      },
      _handleSuccess(e) {
        //成功回调
        // this.resetQuery()
        this.getList()
      },
      
    }
  };

</script>
<style scoped>
  .head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px 0;
  }

  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .listBox_head {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .img_box {
    width: 100px;
    height: 80px;
    border-radius: 4px;
  }

</style>
